package cn.panda.edu.controller;

import cn.panda.edu.model.Major;
import cn.panda.edu.service.MajorService;
import cn.panda.edu.util.Constant;
import cn.panda.edu.util.ResultDataUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/admin")
@Api(description="专业管理")
public class ManageMajorController {
	
	@Autowired
	private MajorService majorService;
	
	/**
	* @Title: queryMajorList 
	* @Description: TODO(分页+根据专业编号或专业名称模糊查询专业列表) 
	* @param majorId
	* @param majorName
	* @param pageIndex
	* @return  
	* PageInfo<Major>
	 */
	@ApiOperation(value ="获取专业列表+分页", notes ="")
	@ApiImplicitParams({
		@ApiImplicitParam(name ="majorId", value ="专业编号", required =false, dataType ="int", paramType ="form"),		
		@ApiImplicitParam(name ="pageIndex", value ="当前页码", required =true, dataType ="int", paramType ="form")
	})
	@RequestMapping(value ="/majormanageFy", method =RequestMethod.POST)
	public Object queryMajorList(Integer condition, int pageIndex){
		PageInfo<Major> pList = majorService.selectByPageAndSelective(condition, pageIndex, Constant.PAGE_SIZE);
		return ResultDataUtil.resData(200, "", pList);
		
	}
	
	/**
	 * 
	* @Title: delMajor 
	* @Description: TODO(管理删除专业信息) 
	* @param majorId
	* @return  
	* Map<String,Object>
	 */
	@ApiOperation(value = "管理删除专业信息", notes = "")
	@ApiImplicitParam(name = "majorId", value = "专业编号", required = true, dataType = "int", paramType = "form")
	@RequestMapping(value = "/majormanageDel", method = RequestMethod.POST)
	public Map<String, Object> delMajor(Integer majorId){
		Map<String, Object> map = new HashMap<>();
		int result = majorService.deleteByPrimaryKey(majorId);
		if(result > 0) {
			map = ResultDataUtil.resData(200, "删除专业信息成功",null) ;
		} else {
			map = ResultDataUtil.resData(500, "删除失败",null) ;
		}
		return map;
	}
	
	/**
	 * 
	* @Title: updateMajor 
	* @Description: TODO(修改专业信息) 
	* @param major
	* @return  
	* Map<String,Object>
	 */
	@ApiOperation(value ="修改专业信息", notes ="")
	@ApiImplicitParam(name ="major", value ="专业实体类major", required = false, dataType ="Major", paramType ="form")
	@RequestMapping(value ="/majormanageUp", method =RequestMethod.POST)
	public Map<String, Object> updateMajor(Major major){
		Map<String, Object> map = new HashMap<>();
		int result = majorService.updateByPrimaryKeySelective(major);
		if(result > 0) {
			map = ResultDataUtil.resData(200, "修改成功",null) ;
		} else {
			map = ResultDataUtil.resData(500, "修改失败",null) ;
		}
		return map;
	}
	
	/**
	 * 
	* @Title: addMajor 
	* @Description: TODO(添加专业信息) 
	* @param major
	* @return  
	* Map<String,Object>
	 */
	@ApiOperation(value ="添加专业信息", notes ="")
	@ApiImplicitParam(name ="major", value ="专业实体类Major", required =false, dataType ="Major",paramType ="form")
	@RequestMapping(value ="/majormanageAdd", method =RequestMethod.POST)
	public Map<String, Object> addMajor(Major major){
		Map<String, Object> map = new HashMap<>();
		int result = majorService.insertSelective(major);
		if(result > 0) {
			map = ResultDataUtil.resData(200, "添加成功",null) ;
		} else {
			map = ResultDataUtil.resData(500, "添加失败",null) ;
		}
		return map;
		
	}
	
	/**	 * 
	* @Title: majormanageSel 
	* @Description: TODO(根据主键查询专业) 
	* @param @param majorId
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="根据主键查询专业" , notes="")//用以指明api名称 
	@ApiImplicitParam(name="majorId", value="专业id", required=true, dataType="int",paramType="form")	
	@RequestMapping(value = "/majormanageSel",method = RequestMethod.POST)
	public Map<String,Object> majormanageSel(@RequestParam(required=true)Integer majorId){
		Major major= majorService.selectByPrimaryKey(majorId);		
		return ResultDataUtil.resData(200, "",major) ;	
	}

	
	@ApiOperation(value="查询所有专业" , notes="")//用以指明api名称 
	@RequestMapping(value = "/majormanageAll",method = RequestMethod.POST)
	public Map<String,Object> majormanageAll(){
		List<Major> mList= majorService.selectAll();			
		return ResultDataUtil.resData(200, "",mList) ;			
	}
	
	
	
	
	
	
}
